<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    h1 {
      height: 1500px;
    }

    p {
      height: 50px;
      width: 50px;
      background-color: #000;
      text-align: center;
      color: aliceblue;
      border-radius: 50%;
      display: none;
    }
  </style>
</head>

<body>
  <h1>返回的内容</h1>
  <p>Top</p>
  <script>
    var p = document.querySelector('p')
    window.onscroll = () => {
      var height = document.documentElement.scrollTop || document.body.scrollTop
      if (height >= 400) {
        p.style.display = 'block';
      } else {
        p.style.display = 'none';
      }
    }
    p.onclick = () => {
      document.body.scrollTop = 0;
      document.documentElement = 0
    }
  </script>
</body>

</html>